﻿<UserControl x:Class="GameListCreator.Controls.GameSelector"
             xmlns:my="clr-namespace:GameListCreator.Controls"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:converters="clr-namespace:GameListCreator.Converters"             
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="400">
    
    <UserControl.Resources>
        <converters:VisibilityConverter x:Key="VisibilityConverter"></converters:VisibilityConverter>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" Margin="10" AllowDrop="True"  Drop="LayoutRoot_Drop">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        
        <DockPanel DockPanel.Dock="Top">

            <my:RoundButton DockPanel.Dock="Right" Content="Remove" IconSource="../Images/Buttons/Delete.png" Opacity="0.5" Margin="5,0,5,0" Click="ButtonRemove_Click" />
            <my:RoundButton DockPanel.Dock="Right" Content="Add" IconSource="../Images/Buttons/Plus.png" Opacity="0.5" Margin="5,0,5,0" Click="ButtonAdd_Click" />

            <TextBlock Text="Select game" Style="{StaticResource TitleForm}" />
            </DockPanel>

            <!--<TextBlock Text="List of games" Style="{StaticResource TextForm}" />-->

            <Grid Grid.Row="1" >

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>

                <DockPanel Grid.Row="0" Margin="10">
                    <!--<my:RoundButton DockPanel.Dock="Right" Margin="5,0,-5,0" IconSource="../Images/Buttons/Search.png" Opacity="0.5"></my:RoundButton>-->
                    <TextBox FontSize="16" Text="{Binding Filter, Mode=TwoWay}" TextChanged="TextBoxSearch_TextChanged"></TextBox>
                </DockPanel>

            <ListBox VirtualizingStackPanel.VirtualizationMode="Recycling" Grid.Row="1" ItemsSource="{Binding GamesFiltered}" SelectedItem="{Binding SelectedGame, Mode=TwoWay}" Margin="10,0,10,10" SelectionMode="Single" BorderBrush="LightGray" BorderThickness="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">

                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>

                    <ListBox.ItemTemplate>
                        <DataTemplate>

                        <Grid>

                            <Grid Margin="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                                    <ColumnDefinition Width="*" ></ColumnDefinition>
                                    <ColumnDefinition Width="Auto" ></ColumnDefinition>
                                </Grid.ColumnDefinitions>

                                <Border Background="LightGray" Width="40" Height="40">
                                    <Image Stretch="UniformToFill" Source="{Binding FrontCoverFullFilename}"></Image>
                                </Border>

                                <StackPanel Grid.Column="1" Margin="10,0,10,0">
                                    <TextBlock Text="{Binding Label, TargetNullValue='Unknown name game'}" TextWrapping="NoWrap" FontSize="15"></TextBlock>

                                    <DockPanel>
                                        <TextBlock Foreground="DarkGray" Text="{Binding Genre, TargetNullValue='Unclassified'}" DockPanel.Dock="Right"></TextBlock>
                                        <TextBlock Foreground="DarkGray" TextWrapping="NoWrap"  Text="{Binding Publisher, TargetNullValue='Unknown publisher'}"></TextBlock>
                                    </DockPanel>
                                </StackPanel>

                                <Image Visibility="{Binding IsChecked, Converter={StaticResource VisibilityConverter}, ConverterParameter=True}" CacheMode="BitmapCache" Grid.Column="2" Margin="5" VerticalAlignment="Center" Width="32" Source="../Images/Buttons/Alert48.png"></Image>

                            </Grid>
                        </Grid>
                    </DataTemplate>
                    </ListBox.ItemTemplate>

                </ListBox>

            <StackPanel Grid.Row="2" Margin="10,0,10,0" Orientation="Horizontal">

                <TextBlock Text="{Binding Games.Count}"></TextBlock>
                <TextBlock Margin="3,0,0,0" Text="games,"></TextBlock>

                <TextBlock Margin="3,0,0,0" Text="{Binding GamesFiltered.Count}"></TextBlock>
                <TextBlock Margin="3,0,0,0" Text="filtered games"></TextBlock>
                
            </StackPanel>
            
            </Grid>
        
    </Grid>
</UserControl>
